package me.heyclock.hl.recordwriter.app;

import android.app.Activity;
import android.view.View;
import android.widget.Toast;

import com.github.nukc.stateview.StateView;

import me.heyclock.hl.recordwriter.controller.BaseView;
import me.heyclock.hl.recordwriter.ui.RotateAnimatorProvider;
import me.imid.swipebacklayout.lib.app.SwipeBackActivity;

/**
 * Created by hl on 2018/4/27.
 */

public class BaseSwipeBackActivity extends SwipeBackActivity implements BaseView {
    /**
     * 进度条
     */
    private StateView stateView;

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    /**
     * des: 设置进度条
     * author: hl
     * @param activity
     */
    protected void setStateView(Activity activity){
        ///< 进度条
        stateView = StateView.inject(activity);
        ///< 自定义了布局，那么自定义一下动画吧...
        stateView.setAnimatorProvider(new RotateAnimatorProvider());
    }

    /**
     * des: 设置进度条+重试监听
     * author: hl
     * @param activity
     * @param onRetryClickListener
     */
    protected void setStateView(Activity activity, StateView.OnRetryClickListener onRetryClickListener){
        ///< 进度条
        stateView = StateView.inject(activity);
        ///< 自定义了布局，那么自定义一下动画吧...
        stateView.setAnimatorProvider(new RotateAnimatorProvider());
        ///< 设置重试事件
        stateView.setOnRetryClickListener(onRetryClickListener);
    }

    /**
     * des: 设置进度条+重试监听
     * author: hl
     * @param view
     * @param onRetryClickListener
     */
    protected void setStateView(View view, StateView.OnRetryClickListener onRetryClickListener){
        ///< 进度条
        stateView = StateView.inject(view);
        ///< 自定义了布局，那么自定义一下动画吧...
        stateView.setAnimatorProvider(new RotateAnimatorProvider());
        ///< 设置重试事件
        stateView.setOnRetryClickListener(onRetryClickListener);
    }

    /**
     * des: 设置进度条
     * author: hl
     * @param view
     */
    protected void setStateView(View view){
        ///< 进度条
        stateView = StateView.inject(view);
        ///< 自定义了布局，那么自定义一下动画吧...
        stateView.setAnimatorProvider(new RotateAnimatorProvider());
    }

    /**
     * 显示内容，目前搜索页面会用到这个接口
     */
    protected void showStateView(){
        stateView.showContent();
    }

    /**
     * 显示空内容，目前搜索页面会用到这个接口
     */
    protected void emptyStateView(){
        stateView.showEmpty();
    }

    /**
     * 显示重试内容，目前搜索页面会用到这个接口
     */
    protected void retryStateView(){
        stateView.showRetry();
    }

    @Override
    public void showDialog() {
        stateView.showLoading();
    }

    @Override
    public void disDialog() {
        stateView.showContent();
    }

    @Override
    public void retryDialog() {
        stateView.showRetry();
    }

    @Override
    public void emptyDialog() {
        stateView.showEmpty();
    }

    @Override
    public void showToast(String msg) {
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
    }
}
